package com.ruoyi.web.controller.english;

import java.util.List;

import com.ruoyi.english.domain.EnPlan;
import com.ruoyi.english.service.IEnPlanService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 复习计划Controller
 * 
 * @author ruoyi
 * @date 2021-12-25
 */
@RestController
@RequestMapping("/english/plan")
public class EnPlanController extends BaseController
{
    @Autowired
    private IEnPlanService enPlanService;

    /**
     * 查询复习计划列表
     */
    @PreAuthorize("@ss.hasPermi('english:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnPlan enPlan)
    {
        startPage();
        List<EnPlan> list = enPlanService.selectEnPlanList(enPlan);
        return getDataTable(list);
    }

    /**
     * 导出复习计划列表
     */
    @PreAuthorize("@ss.hasPermi('english:plan:export')")
    @Log(title = "复习计划", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EnPlan enPlan)
    {
        List<EnPlan> list = enPlanService.selectEnPlanList(enPlan);
        ExcelUtil<EnPlan> util = new ExcelUtil<EnPlan>(EnPlan.class);
        return util.exportExcel(list, "复习计划数据");
    }

    /**
     * 获取复习计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('english:plan:query')")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId)
    {
        return AjaxResult.success(enPlanService.selectEnPlanByPlanId(planId));
    }

    /**
     * 新增复习计划
     */
    @PreAuthorize("@ss.hasPermi('english:plan:add')")
    @Log(title = "复习计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnPlan enPlan)
    {
        return toAjax(enPlanService.insertEnPlan(enPlan));
    }

    /**
     * 修改复习计划
     */
    @PreAuthorize("@ss.hasPermi('english:plan:edit')")
    @Log(title = "复习计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnPlan enPlan)
    {
        return toAjax(enPlanService.updateEnPlan(enPlan));
    }

    /**
     * 删除复习计划
     */
    @PreAuthorize("@ss.hasPermi('english:plan:remove')")
    @Log(title = "复习计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(enPlanService.deleteEnPlanByPlanIds(planIds));
    }
}
